package com.cy.jt.demo.service;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MemoryService {

    //本地缓存(JVM内部的缓存)
//    private Map<String,Object>  cache= new ConcurrentHashMap();
    @Cacheable("myCache") //由此这个月描述的方法为缓存切入点
    public List<Map<String,Object>> list(){
//        if(cache.containsKey("memoryKey"))//将来这个key为参数列表的组合
//            return (List<Map<String,Object>>)cache.get("memoryKey");
        System.out.println("cnm");
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("id",10);
        hashMap.put("name","二狗");
        HashMap<String, Object> hashMap1 = new HashMap<>();
        hashMap1.put("id",10);
        hashMap1.put("name","二狗");

        List<Map<String,Object>> arrayList = new ArrayList<>();
        arrayList.add(hashMap);
        arrayList.add(hashMap1);
//        cache.put("memoryKey",arrayList);
        return arrayList;

    }
}
